<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Runnable vs Callable - Java并发编程核心接口对比</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 1rem 1.5rem;
            border-radius: 8px;
            margin: 1rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                Runnable vs Callable
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                深入理解Java并发编程中的两大核心接口
            </p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-code mr-2"></i>
                    <span>异步执行</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-sync-alt mr-2"></i>
                    <span>并发编程</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-layer-group mr-2"></i>
                    <span>线程池集成</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">R</span>unnable和Callable是Java中的两个接口，常用于并发编程中执行任务。虽然它们的功能有一些相似之处，但它们之间存在关键的区别。理解这些区别对于编写高效的并发程序至关重要。
            </p>
        </section>

        <!-- Visual Comparison Diagram -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <h2 class="text-3xl font-bold mb-6 text-center text-gray-800">
                <i class="fas fa-diagram-project mr-3 feature-icon"></i>
                接口关系图
            </h2>
            <div class="mermaid">
                graph TD
                    A[Java并发任务接口] --> B[Runnable]
                    A --> C[Callable]
                    B --> D[void run&#40;&#41;]
                    C --> E[T call&#40;&#41; throws Exception]
                    D --> F[无返回值]
                    D --> G[不能抛出受检异常]
                    E --> H[有返回值]
                    E --> I[可以抛出受检异常]
                    B --> J[Thread类]
                    B --> K[ExecutorService]
                    C --> L[ExecutorService]
                    L --> M[Future对象]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#ed8936,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </section>

        <!-- Key Differences -->
        <section class="grid md:grid-cols-2 gap-8 mb-12">
            <!-- Runnable Card -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover animate-fadeInUp">
                <div class="flex items-center mb-6">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-running text-3xl text-green-600"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800">Runnable 接口</h3>
                </div>
                
                <div class="space-y-4">
                    <div class="highlight-box">
                        <h4 class="font-semibold text-lg mb-2">方法签名</h4>
                        <code class="text-purple-600 font-mono">void run()</code>
                    </div>
                    
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">无返回值</p>
                                <p class="text-gray-600 text-sm">适合执行不需要返回结果的简单任务</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">不能抛出受检异常</p>
                                <p class="text-gray-600 text-sm">异常必须在方法内部处理</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <i class="fas fa-cog text-blue-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">使用场景</p>
                                <p class="text-gray-600 text-sm">打印日志、更新状态、简单的后台任务</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Callable Card -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover animate-fadeInUp" style="animation-delay: 0.2s">
                <div class="flex items-center mb-6">
                    <div class="w-16 h-16 bg-orange-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-phone-alt text-3xl text-orange-600"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-gray-800">Callable 接口</h3>
                </div>
                
                <div class="space-y-4">
                    <div class="highlight-box">
                        <h4 class="font-semibold text-lg mb-2">方法签名</h4>
                        <code class="text-purple-600 font-mono">T call() throws Exception</code>
                    </div>
                    
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">有返回值</p>
                                <p class="text-gray-600 text-sm">可以返回任意类型的结果</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">可以抛出受检异常</p>
                                <p class="text-gray-600 text-sm">更灵活的错误处理机制</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <i class="fas fa-cog text-blue-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold">使用场景</p>
                                <p class="text-gray-600 text-sm">计算任务、数据库查询、网络请求</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Examples -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">
                <i class="fas fa-code mr-3 feature-icon"></i>
                代码示例
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Runnable Example -->
                <div>
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-terminal mr-2 text-green-600"></i>
                        Runnable 示例
                    </h3>
                    <div class="code-block">
                        <pre><code class="language-java">Runnable task = () -> {
    System.out.println("Task is running");
};
new Thread(task).start();</code></pre>
                    </div>
                </div>
                
                <!-- Callable Example -->
                <div>
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-terminal mr-2 text-orange-600"></i>
                        Callable 示例
                    </h3>
                    <div class="code-block">
                        <pre><code class="language-java">Callable<Integer> task = () -> {
    return 123;
};
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> future = executor.submit(task);
Integer result = future.get(); // 获取返回值</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Thread Pool Integration -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">
                <i class="fas fa-swimming-pool mr-3 feature-icon"></i>
                与线程池的集成
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-gray-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-green-700">
                        <i class="fas fa-running mr-2"></i>
                        Runnable 与线程池
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-3"></i>
                            <span>可以通过 ExecutorService 提交执行</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-3"></i>
                            <span>submit() 方法返回的 Future 对象值为 null</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-3"></i>
                            <span>适合"发射后不管"的任务模式</span>
                        </li>
                    </ul>
                </div>
                
                